<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>线下还款申请记录表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox col_50">
                    <div class="label">合同号</div>
                    <div class="field">
                        <input name="crCntNo" id="crCntNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">还款状态</div>
                    <div class="field">
                        <select name="applyStsCd" id="applyStsCd" data-value=""
                                validate="{required:true,select:true}" class="l-selected">
                            <option value=" ">--请选择--</option>
                            <c:forEach items="${applyStsCdList}" var="item">
                                <option value="${item.key }">${item.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">资方</div>
                    <div class="field">
                        <select name="loanChannel" id="loanChannel" data-value=""
                                validate="{required:true,select:true}" class="l-selected">
                            <option value=" ">--请选择--</option>
                            <option value="YLYH">亿联银行</option>
                            <option value="SYYH">上农小贷</option>
                            <option value="WKXT">五矿信托</option>
                            <option value="YNXT">云南信托</option>
                            <option value="LHYH">蓝海银行</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_100" >
                    <div class="label">创建时间</div>
                    <div class="field">
                        <input name="stDt" id="stDt" type="text" class="ui-datepicker" value="">
                        <span>---</span>
                        <input name="endDt" id="endDt" type="text" class="ui-datepicker" value="">
                    </div>
                </div>

				<div class="fieldBox col_100" >
                    <div class="label">完成时间</div>
                    <div class="field">
                        <input name="stFinDt" id="stFinDt" type="text" class="ui-datepicker" value="">
                        <span>---</span>
                        <input name="endFinDt" id="endFinDt" type="text" class="ui-datepicker" value="">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_1"></i>查询</span>
                    <span id="clearBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_19"></i>清空</span>
                    <span id="addBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_3"></i>新增还款申请</span>
<%--                    <span id="changeBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_4"></i>修改还款申请</span>--%>
                    <span id="delBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_7"></i>删除</span>
                    <span id="addFundBtn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_2"></i>绑定资金还款</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div class="sqPanel" style="margin-bottom: 0;">
        <div class="sqPanel_head">
            <table class="table_full">
                <tr>
                    <td><b>总金额(元): </b><span id="sumAmt"/></td>
                    <td><b>本息罚金额和(元): </b><span id="sumCIPAmt"/></td>
                </tr>
            </table>
        </div>
        <div class="sqPanel_body">
    		<div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var grid = null, menu = null;
	$("#searchBar").ligerForm();

    getSumAmt();
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/repay/insOfflineRepayLog/initList.do',
            method: 'get',
            columns: [
                {display: '主键ID', name: 'id', minWidth: 100, align: 'left', enabledSort: false},
                /*{display: '账单ID', name: 'billId', minWidth: 100, align: 'left', enabledSort: false},*/
                {display: '还款合同号', name: 'crCntNo', minWidth: 100, align: 'left', enabledSort: false},
                {display: '线下实还时间', name: 'actPayDt', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '还款类型', name: 'repayTypCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '还款金额', name: 'repayAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.repayAmt/100);
                    }
                },
                {display: '实还本金', name: 'capAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.capAmt/100);
                    }
                },
                {display: '实还利息', name: 'intrAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.intrAmt/100);
                    }
                },
                {display: '实还罚息', name: 'pntAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.pntAmt/100);
                    }
                },
                {display: '实还正常保费', name: 'grtAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.grtAmt/100);
                    }
                },
                {display: '实还逾期保费', name: 'ovdGrtAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.ovdGrtAmt/100);
                    }
                },
                {display: '实还违约金', name: 'damAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        return '&yen;'+FormatMoney(rowdata.damAmt/100);
                    }
                },
                {display: '申请还款流水号', name: 'applySeqNo', minWidth: 100, align: 'left', enabledSort: false},
                {display: '贷款渠道编码', name: 'loanChannel', minWidth: 100, align: 'left', enabledSort: false},
                {display: '还款状态', name: 'applyStsCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '失败原因', name: 'applyRem', minWidth: 100, align: 'left', enabledSort: false},
                {display: '完成时间', name: 'applyFinTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            detail: {
                height: 'auto',
                    onShowDetail: showDetails
            },
            frozen:false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            getSumAmt();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "*Cd": 	" ",
            });
            liger.get("loanChannel").clear();
            liger.get("applyStsCd").clear();
        });
        
        var callback = function () {
            grid.reload();
        };

        /**
         * 展开List
         * @param row
         * @param detailPanel
         * @param callback
         */
        function showDetails(row, detailPanel, callback) {
            var gridBox = document.createElement('div');
            $(gridBox).css('margin', 10);
            $(detailPanel).css({
                'padding': 10,
                'box-sizing': 'border-box'
            }).append(gridBox);
            detailGrid = $(gridBox).ligerGrid({
                url: '<%=path%>/repay/insOfflineRepayDtl/initList.do?applyLogId=' + row.id,
                method: 'get',
                columns: [
                    /*{display: '线下还款申请记录ID', name: 'applyLogId', minWidth: 100, align: 'left', enabledSort: false},
                    {display: '账单明细ID', name: 'billDtlId', minWidth: 100, align: 'left', enabledSort: false},*/
                    {display: '期次', name: 'payPd', minWidth: 100, align: 'left', enabledSort: false},
                    {display: '本金', name: 'capAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.capAmt/100);
                        }
                    },
                    {display: '利息', name: 'intrAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.intrAmt/100);
                        }
                    },
                    {display: '罚息', name: 'pntAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.pntAmt/100);
                        }
                    },
                    {display: '担保费', name: 'grtAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.grtAmt/100);
                        }
                    },
                    {display: '逾期担保费', name: 'ovdGrtAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.ovdGrtAmt/100);
                        }
                    },
                    {display: '违约金', name: 'damAmt', minWidth: 100, align: 'right', enabledSort: false,
                        render:function(rowdata,index,value){
                            return '&yen;'+FormatMoney(rowdata.damAmt/100);
                        }
                    },
                ],
                root: 'rows',
                hideLoadButton: true,
                width: '100%',
                height: 'auto',
                isScroll: false,
                rownumbers: true,  //显示序号
                checkbox: false,
                allowUnSelectRow: true,
                alternatingRow: false,
                onAfterShowData: callback,
                frozen: false,
                usePager: false
            });
        }

        /* 新增 */
        $("#addBtn").click(function (event) {
            Add_navTab("InsOfflineRepayLog_1", "新增线下还款申请记录表", '<%=path%>/repay/insOfflineRepayLog/toAddPage.do', callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id=selectedRows[0].id;
            Add_navTab('InsOfflineRepayLog_2'+_id, "修改线下还款申请记录表", '<%=path%>/repay/insOfflineRepayLog/toModifyPage.do?id='+_id, callback);
        });

        /* 删除 */
        $("#delBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/repay/insOfflineRepayLog/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

        /* 绑定资金还款 */
        $("#addFundBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id = selectedRows[0].id;
            Add_navTab("InsOfflineRepayLog_3", "新增绑定资金表", '<%=path%>/repay/insOfflineFundDtl/toAddPage.do?id='+_id, callback);
        });

    });

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    function getSumAmt() {
    	var form = new liger.get("searchBar");
        var data = form.getData();
        $.ajax({
            type: 'get',
            dataType: 'json',
            data: data,
            url: '<%=path%>/repay/insOfflineRepayLog/sumRepayData.do',
            success: function (msg) {
                $("#sumAmt").text(FormatMoney(msg.SUMAMT / 100));
                $("#sumCIPAmt").text(FormatMoney(msg.SUMCIPAMT / 100));
            }
        });
    }
</script>

</body>
</html>
